﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsWareHouseDAL.cs
/// 作  者：SAM
/// 时  间：2006.11.16
/// 说  明：ClsWareHouseDAL类用于仓库设置信息相关处理
/// </summary>
public class ClsWareHouseDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    /// <summary>
    /// 用于查询窗口获取数据
    /// </summary>
    /// <returns></returns>
    public DataSet SearchWareHouseByQueryFrom(string UserID)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_QueryWinGetDataByWareHouse", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@u_log_id", SqlDbType.NVarChar, 60);
        dat.SelectCommand.Parameters["@u_log_id"].Value = UserID;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    //得到仓库盘点商品信息
    public DataSet SearchWareHouses(string strCheck)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_QueryWinGetDataByCheckStore", con);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }


    //得到仓库盘点商品库存信息
    //--CREATE BY KIDY ON 20061215
    public decimal getWareHouseQty(string sIm_no,string sBatch_no,string sStore_id)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        //SqlDataAdapter dat = new SqlDataAdapter("Pro_QueryCheckStoreQty", con);
        SqlCommand com = new SqlCommand("Pro_QueryCheckStoreQty", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@Im_no", SqlDbType.NVarChar, 30);
        com.Parameters["@Im_no"].Value = sIm_no;
        com.Parameters.Add("@Batch_no", SqlDbType.NVarChar, 30);
        com.Parameters["@Batch_no"].Value = sBatch_no;
        com.Parameters.Add("@Store_id", SqlDbType.NVarChar, 30);
        com.Parameters["@Store_id"].Value = sStore_id;
        try
        {
            con.Open();
        
            return decimal.Parse(com.ExecuteScalar().ToString());
        }
        catch
        {
            return 0;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }
}
